//按钮点击效果
(function(){
function clickResponse(lei){
	lei.addEventListener("touchstart",function(){
		lei.classList.add("clickResponse");
	});
	lei.addEventListener("touchend",function(){
		lei.classList.remove("clickResponse");
	});
}
var addShop = document.querySelector(".addShop");
var a1 = document.querySelector(".a1");
var a2 = document.querySelector(".a2");
var a3 = document.querySelector(".a3");
var a4 = document.querySelector(".a4");
var a5 = document.querySelector(".a5");
var a6 = document.querySelector(".a6");
var a7 = document.querySelector(".a7");
var a8 = document.querySelector(".a8");
var a9 = document.querySelector(".a9");
var a10 = document.querySelector(".a10");
var a11 = document.querySelector(".a11");
var a12 = document.querySelector(".a12");
var a13 = document.querySelector(".a13");
var a14 = document.querySelector(".a14");
var a15 = document.querySelector(".a15");
clickResponse(addShop);
clickResponse(a1);
clickResponse(a2);
clickResponse(a3);
clickResponse(a4);
clickResponse(a5);
clickResponse(a6);
clickResponse(a7);
clickResponse(a8);
clickResponse(a9);
clickResponse(a10);
clickResponse(a11);
clickResponse(a12);
clickResponse(a13);
clickResponse(a14);
clickResponse(a15);
})();

//添加商品按钮mask
(function(){
var addMask = document.querySelector(".addMask");
var moreMask = document.querySelector(".moreMask");
var addShop = document.querySelector(".addShop");
var canel = document.querySelector(".canel");
var btn = document.querySelector(".btn");
var moreCanel = document.querySelector(".moreCanel");
var showMore = document.querySelector(".showMore");
addShop.addEventListener("click",function(){
	addMask.style.display="block";
});
canel.addEventListener("click",function(){
		addMask.style.display="none";
});
showMore.addEventListener("click",function(){
	moreMask.style.display="block";
});
moreCanel.addEventListener("click",function(){
	moreMask.style.display="none";
});
})();


//AJAX传参
(function(){
var xhr = new XMLHttpRequest();
	xhr.addEventListener("readystatechange", function(e) {
		if(xhr.readyState == 4 && e.target.status == 200) {
			getData(e.target.response);
			getVisitor(e.target.response);
			getOrder(e.target.response);
			getSale(e.target.response);
		}
	});
	xhr.open("GET", "https://www.easy-mock.com/mock/5bad9911cc76e634e0ab9e28/xyfs/UserMsg");
	xhr.send();
	//累计收入AJAX请求
	function getData(responce) {
		var allMoney = document.querySelector(".allMoney");
		var dataObj = JSON.parse(responce);
		var template = function(money) {
			return `
						<p class="money">${money}</p>
						<p>累计收入</p>
					`
		};
		var aa = document.createElement("a");
		aa.classList.add("flex");
		aa.innerHTML = template(dataObj.mai.index.money);
		allMoney.appendChild(aa);
	};
	//昨日访客AJAX请求
	function getVisitor(responce){
		var userMsgMore= document.querySelector(".userMsgMore");
		var dataObj = JSON.parse(responce);
		//昨日访客AJAX请求
		var template1 = function(visitor) {
			return `
					<p class="visitor p-fs">${visitor}</p>
					<p class="p-fs-text">昨日访客</p>
			`
		};
		var bb = document.createElement("a");
		bb.classList.add("flex");
		bb.innerHTML = template1(dataObj.mai.index.visitor);
		userMsgMore.appendChild(bb);
	};
	//订单AJAX请求
	function getOrder(responce){
		var userMsgMore= document.querySelector(".userMsgMore");
		var dataObj = JSON.parse(responce);
		//昨日访客AJAX请求
		var template2 = function(order) {
			return `
					<p class="Order p-fs">${order}</p>
					<p class="p-fs-text">七日订单</p>
			`
		};
		var cc = document.createElement("a");
		cc.classList.add("flex");
		cc.innerHTML = template2(dataObj.mai.index.order);
		userMsgMore.appendChild(cc);
	};
	//销量AJAX请求
	function getSale(responce){
		var userMsgMore= document.querySelector(".userMsgMore");
		var dataObj = JSON.parse(responce);
		//昨日访客AJAX请求
		var template3 = function(sales) {
			return `
					<p class="Sales p-fs">￥${sales}</p>
					<p class="p-fs-text">七日销量</p>
			`
		};
		var dd = document.createElement("a");
		dd.classList.add("flex");
		dd.innerHTML = template3(dataObj.mai.index.sales);
		userMsgMore.appendChild(dd);
	};
})();
